Skip to content

fix: move PowerOff/Reboot before prepareShutdown to avoid shutdown race - #240

Draft
BLumia wants to merge 1 commit into
masterfrom
fix/dde-session-shutdown-race-condition
Draft

BLumia wants to merge 1 commit into
masterfrom
fix/dde-session-shutdown-race-condition

Conversation

@BLumia

@BLumia BLumia commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

修复内容

调整 shutdown() 和 reboot() 方法中的执行顺序,将 m_login1ManagerInter->PowerOff(false) / Reboot(false) 调用移到 prepareShutdown(force) 之前。

根因

prepareShutdown() 会启动 dde-session-shutdown.target,该 target 声明了 Conflicts=dde-session-manager.service。systemd 在解析冲突时会停止 dde-session-manager.service(即当前正在执行 shutdown() 的进程),导致 PowerOff(false) / Reboot(false) 可能在被调用前进程就被杀掉。

竞态路径:

  • 路径 A(代码继续执行):prepareShutdown() → clearCurrentTty() → PowerOff()(同步、快速)
  • 路径 B(systemd 停止服务):shutdown target 被 start → 冲突解析 → systemd 停止 dde-session-manager.service → SIGTERM(异步链路)

当路径 B 先到达时,进程被 SIGTERM 杀死,PowerOff() 永远不会执行,导致屏幕黑屏但主机不断电。

修复方案

将 PowerOff(false) / Reboot(false) 移到 prepareShutdown(force) 之前,确保 login1 先收到关机/重启请求,不受 session 拆解竞态影响。

关联 Issue

DDE-490

Summary by Sourcery

Bug Fixes:

  • Ensure power-off and reboot requests are sent before session shutdown begins, preventing shutdown races that could leave the host powered on.

prepareShutdown() starts dde-session-shutdown.target which declares
Conflicts=dde-session-manager.service. systemd stops the current process
before PowerOff/Reboot is called, causing the machine to black-screen but
not power off. Moving the login1 PowerOff/Reboot call before
prepareShutdown() ensures the shutdown/reboot request is received first.

DDE-490
@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR fixes a shutdown race by initiating the login1 PowerOff/Reboot request before prepareShutdown can start the systemd shutdown target and stop dde-session-manager.service, ensuring the host power action is requested before the session manager may be terminated.

Sequence diagram for the fixed shutdown and reboot ordering

sequenceDiagram
    participant SessionManager
    participant login1
    participant systemd
    participant SessionService as dde-session-manager.service

    alt shutdown
        SessionManager->>login1: PowerOff(false)
    else reboot
        SessionManager->>login1: Reboot(false)
    end
    SessionManager->>SessionManager: prepareShutdown(force)
    SessionManager->>systemd: start dde-session-shutdown.target
    systemd->>SessionService: stop service
    SessionManager->>SessionManager: clearCurrentTty()
    login1-->>SessionManager: QDBusPendingReply
Loading

File-Level Changes

Change Details Files
Reorder shutdown and reboot sequencing so the login1 power-management request is issued before session shutdown begins.
  • Send the asynchronous D-Bus PowerOff/Reboot request immediately after starting the black widget.
  • Run prepareShutdown and clear the current TTY only after the request has been initiated.
  • Retain existing pending-reply error logging after shutdown preparation.
src/dde-session/impl/sessionmanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants